<template>
	<view class="apply-pages pt-md" :style="{background:pageColor}">
		<block v-if="isLoad">
			<view class="apply-form">
				<view class="fill-base radius-16">
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>姓名</view>
						<input v-model="form.coach_name" type="text" class="item-input flex-1" maxlength="15"
							:placeholder="rule[0].errorMsg" />
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b" v-if="configInfo.plugAuth.industrytype == 3">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>职业分类
						</view>
						<view class="flex-1 flex-center">
							<input :disabled="true" v-model="industryInfo.title" class="item-input flex-1" />
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>性别</view>
						<view class="item-input flex-1 flex-y-center">
							<view @tap.stop="form.sex = index" class="flex-y-center" :class="[{'mr-lg':index==0}]"
								:style="{color:form.sex == index ? primaryColor:''}" v-for="(item,index) in ['男','女']"
								:key="index"><i class="iconfont icon-xuanze mr-sm"
									:class="[{'icon-xuanze-fill':form.sex == index}]"></i>{{item}}
							</view>
						</view>
					</view>
					<block v-if="industryInfo.height">
						<view class="flex-between pl-lg pr-lg b-1px-b">
							<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>身高
							</view>
							<view class="flex-1 flex-center">
								<input v-model="form.height" type="number" class="item-input flex-1"
									:placeholder="rule[2].errorMsg" />
								<view class="c-title">cm</view>
							</view>
						</view>
					</block>
					<block v-if="industryInfo.weight">
						<view class="flex-between pl-lg pr-lg b-1px-b">
							<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>体重
							</view>
							<view class="flex-1 flex-center">
								<input v-model="form.weight" type="digit" class="item-input flex-1"
									:placeholder="rule[3].errorMsg" />
								<view class="c-title">kg</view>
							</view>
						</view>
					</block>
					<view class="flex-between ml-lg mr-lg b-1px-b" v-if="industryInfo.birthday">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>生日</view>
						<view class="item-input text flex-1">
							<picker @change="pickerChange($event,'birthday')" mode="date" :value="form.birthday">
								<view class="flex-between">
									{{form.birthday||'请选择'}}
									<i class="iconfont icon-right ml-sm" style="font-size: 28rpx;"></i>
								</view>
							</picker>
						</view>
					</view>
					<block v-if="form.birthday && industryInfo.constellation">
						<view class="flex-between pl-lg pr-lg b-1px-b">
							<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>星座
							</view>
							<view class="flex-1 flex-center">
								<input :disabled="true" v-model="form.constellation" class="item-input flex-1" />
							</view>
						</view>
					</block>
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>手机号</view>
						<input v-model="form.mobile" type="text" class="item-input flex-1" maxlength="11"
							:placeholder="rule[5].errorMsg" />
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b"
						v-if="configInfo.short_code_status && form.mobile.length==11 &&form.mobile !== old_phone">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>验证码</view>
						<view class="flex-between">
							<input v-model="form.short_code" type="text" class="item-input flex-1" maxlength="6"
								placeholder="请输入验证码" />
							<view @tap.stop="toSend" :style="{color:primaryColor}">
								{{authTime>0?`重新获取(${authTime}s)`:'获取验证码'}}
							</view>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b" v-if="industryInfo.employment_years">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>从业年份
						</view>
						<view class="flex-1 flex-center">
							<input v-model="form.work_time" type="number" class="item-input flex-1"
								:placeholder="rule[6].errorMsg" />
							<view class="c-title">年</view>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>意向工作城市
						</view>
						<view class="flex-1 flex-center" v-if="form.admin_id && !configInfo.agent_update_city">
							<input :disabled="true" v-model="form.city" class="item-input flex-1" />
						</view>
						<view class="item-input text flex-1" v-else>
							<picker @change="pickerChange($event,'city')" :value="cityIndex" :range="cityList"
								range-key="title">
								<view class="flex-between">
									{{cityIndex!=-1?cityList[cityIndex].title:'请选择'}}
									<i class="iconfont icon-right ml-sm" style="font-size: 28rpx;"></i>
								</view>
							</picker>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b" v-if="configInfo.plugAuth.career">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>职业类型
						</view>
						<view class="item-input text flex-1">
							<picker @change="pickerChange($event,'type')" :value="typeIndex" :range="typeList"
								range-key="title">
								<view class="flex-between">
									<view class="max-400 ellipsis">
										{{typeIndex!=-1?typeList[typeIndex].title:'请选择'}}
									</view>
									<i class="iconfont icon-right ml-sm" style="font-size: 28rpx;"></i>
								</view>
							</picker>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b" v-if="configInfo.plugAuth.industrytype == 3">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>岗位标签
						</view>
						<view class="item-input text flex-1">
							<picker @change="pickerChange($event,'station')" :value="stationIndex" :range="stationList"
								range-key="title">
								<view class="flex-between">
									{{stationIndex!=-1?stationList[stationIndex].title:'请选择'}}
									<i class="iconfont icon-right ml-sm" style="font-size: 28rpx;"></i>
								</view>
							</picker>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text flex-y-center">个性标签</view>
						<view class="item-input text flex-1">
							<picker @change="pickerChange($event,'personality')" :value="personalityIndex"
								:range="personalityList" range-key="title">
								<view class="flex-between">
									{{personalityIndex!=-1?personalityList[personalityIndex].title:'请选择'}}
									<i class="iconfont icon-right ml-sm" style="font-size: 28rpx;"></i>
								</view>
							</picker>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b"
						v-if="configInfo.plugAuth.store && (form.admin_id || form.store_name)">
						<view class="item-text">挂靠门店</view>
						<view class="item-input text flex-1">
							<view @tap.stop="form.admin_id ? $util.goUrl({url:`/technician/pages/choose-store`}):``"
								class="flex-between">
								<view>{{form.store_name || `请选择`}}</view>
								<i class="iconfont icon-right ml-sm" style="font-size: 28rpx;" v-if="form.admin_id"></i>
							</view>
						</view>
					</view>
					<block v-if="faree_info.free_fare_bear">
						<view class="flex-between pl-lg pr-lg b-1px-b">
							<view class="item-text" style="height:auto">免出行费半径距离</view>
							<view class="flex-1 flex-center">
								<input v-model="form.free_fare_distance" type="digit" class="item-input flex-1"
									:placeholder="rule[10].errorMsg" />
								<view class="c-title">km</view>
							</view>
						</view>
					</block>
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>所在地址
						</view>
						<view class="item-input text flex-1">
							<view @tap.stop="toChooseLocation" class="flex-between">
								<view>{{form.address || `点击右边图标设置`}}</view>
								<i class="iconfont iconjuli ml-sm" :style="{color: primaryColor}"></i>
							</view>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b" v-if="configInfo.plugAuth.dispatchother">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>人员工价
						</view>
						<view class="flex-1 flex-center">
							<input v-model="form.min_price" type="number" class="item-input flex-1 text-center"
								placeholder="请输入最低价" />
							<text class="pl-sm pr-sm">-</text>
							<input v-model="form.max_price" type="number" class="item-input flex-1 text-center"
								placeholder="请输入最高价" />
						</view>
					</view>
				</view>
				<view class="fill-base mt-md radius-16">
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text flex-y-center" style="width:auto"><i
								class="iconfont icon-required c-warning"></i>{{$t('action.attendantName')}}简介</view>
						<input :disabled="true" type="text" class="item-input flex-1" />
					</view>
					<textarea v-model="form.text" class="item-textarea pd-lg" maxlength="300"
						:placeholder="rule[12].errorMsg" />
					<view class="text-right pb-lg pr-lg">
						{{form.text.length>300?300:form.text.length}}/300
					</view>
				</view>
				<view class="fill-base mt-md radius-16">
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>身份证号
						</view>
						<input v-model="form.id_code" type="text" class="item-input flex-1"
							:placeholder="rule[13].errorMsg" />
					</view>
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>真实姓名
						</view>
						<input v-model="form.true_user_name" type="text" class="item-input flex-1" maxlength="10"
							:placeholder="rule[14].errorMsg" />
					</view>
				</view>
				<view class="fill-base mt-md radius-16">
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text tips flex-y-center"><i class="iconfont icon-required c-warning"></i>身份证照片
						</view>
						<view class="item-input flex-1">图片大小不超过10M</view>
					</view>
					<view class="flex-between pl-lg pr-lg pb-md">
						<upload @upload="imgUpload" :imagelist="form.id_card" imgtype="id_card" imgclass="md"
							text="身份证人像面" :imgsize="1"></upload>
						<upload @upload="imgUpload" :imagelist="form.id_card_fan" imgtype="id_card_fan" imgclass="md"
							text="身份证国徽面" :imgsize="1"></upload>
					</view>
					<view class="flex-between pl-lg pr-lg pb-md">
						<upload @upload="imgUpload" :imagelist="form.id_card_people" imgtype="id_card_people"
							imgclass="md" text="手持身份证照片" :imgsize="1"></upload>
					</view>
				</view>
				<view class="fill-base mt-md radius-16" v-if="industryInfo.qualification">
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text tips flex-y-center"><i class="iconfont icon-required c-warning"></i>资格证书
						</view>
						<view class="item-input flex-1">图片大小不超过10M</view>
					</view>
					<view class="flex-between pl-lg pr-lg pb-md">
						<upload @upload="imgUpload" @del="imgUpload" :imagelist="form.license" imgtype="license"
							text="上传图片" :imgsize="15">
						</upload>
					</view>
				</view>
				<view class="fill-base mt-md radius-16">
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text tips flex-y-center"><i class="iconfont icon-required c-warning"></i>工作形象照
						</view>
						<view class="item-input flex-1">图片建议尺寸: 750 * 750，大小不超过10M</view>
					</view>
					<view class="flex-between pl-lg pr-lg pb-md">
						<upload @upload="imgUpload" :imagelist="form.work_img" imgtype="work_img" text="上传图片"
							:imgsize="1">
						</upload>
					</view>
				</view>
				<view class="fill-base mt-md radius-16">
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text tips flex-y-center"><i
								class="iconfont icon-required c-warning"></i>{{$t('action.lifeText')}}
						</view>
						<view class="item-input flex-1">图片建议尺寸: 750 * n，大小不超过10M</view>
					</view>
					<view class="flex-between pl-lg pr-lg pb-md">
						<upload @upload="imgUpload" @del="imgUpload" :imagelist="form.self_img" filetype="picture"
							imgtype="self_img" text="上传图片" :imgsize="9">
						</upload>
					</view>
				</view>
				<view class="fill-base mt-md radius-16">
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text tips">个人视频介绍</view>
						<view class="item-input flex-1">视频大小不超过50M</view>
					</view>
					<view class="flex-between pl-lg pr-lg pb-md">
						<upload @upload="imgUpload" @del="imgUpload" :imagelist="form.video" filetype="video"
							imgtype="video" text="上传视频" :imgsize="1">
						</upload>
					</view>
				</view>
				<view class="flex-center f-caption c-caption pd-lg">
					编辑资料将进入重新审核，审核通过之前将显示原资料
				</view>
			</view>

			<view class="space-max-footer"></view>

			<fix-bottom-button @confirm="submit" :text="[{text:'确定申请',type:'confirm'}]" bgColor="#fff">
			</fix-bottom-button>

		</block>
		<!-- #ifdef MP-WEIXIN -->
		<user-privacy ref="user_privacy" :show="false"></user-privacy>
		<!-- #endif -->
		<!-- #ifdef APP-PLUS -->
		<longbingbing-app-check-auth type="location" ref="app_check_item"
			@confirm="toConfirmChooseLoca"></longbingbing-app-check-auth>
		<!-- #endif -->
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				isLoad: false,
				options: {},
				industryInfo: {},
				cityList: [],
				cityIndex: -1,
				typeList: [],
				typeIndex: -1,
				stationIndex: -1,
				stationList: [],
				personalityIndex: -1,
				personalityList: [],
				old_phone: '',
				authTime: 0,
				timer: null,
				coach_status: 0,
				faree_info: {},
				oldData: {},
				form: {
					id: 0,
					admin_id: 0,
					coach_name: '', //姓名 
					industry_type: '',
					mobile: '', //手机号 
					short_code: '',
					sex: 0, //性别 
					height: '',
					weight: '',
					birthday: '',
					constellation: '',
					work_time: '', //从业年份 
					city_id: '', //城市 
					city: '',
					type_id: '',
					station_icon: '', // 岗位标签
					personality_icon: '',
					store: [], //门店
					store_name: '',
					free_fare_distance: '',
					lng: '',
					lat: '',
					address: '', //详细地址
					min_price: '',
					max_price: '',
					text: '', //备注 
					id_code: '', //身份证号
					true_user_name: '', //真实姓名
					id_card: [], //身份证
					id_card_fan: [], // 身份证反面
					id_card_people: [], //手持身份证
					license: [], //资格证书
					work_img: [], // 工作照
					self_img: [], // 生活-照
					video: [],
					is_work: '',
					start_time: '',
					end_time: '',
					show_salenum: 0,
					order_num: '',
					virtual_collect: '',
					virtual_comment: '',
					custom_balance: ''
				},
				rule: [{
						name: "coach_name",
						checkType: "isNotNull",
						errorMsg: "请输入您的姓名",
						regType: 2
					}, {
						name: "industry_type",
						checkType: "isNotNull",
						errorMsg: "请选择职业分类",
					}, {
						name: "height",
						checkType: "isNumber",
						errorMsg: "请输入您的身高",
						regType: 2
					}, {
						name: "weight",
						checkType: "isFloatNum",
						errorMsg: "请输入您的体重",
						regType: 1,
						dotLen: 1,
						maxNum: '',
						unit: 'kg'
					}, {
						name: "birthday",
						checkType: "isNotNull",
						errorMsg: "请选择您的生日",
						regType: 2
					}, {
						name: "mobile",
						checkType: "isMobile",
						errorMsg: "请输入手机号"
					}, {
						name: "work_time",
						checkType: "isNumber",
						errorMsg: "请输入从业年份，例如：5",
						regType: 2
					}, {
						name: "city_id",
						checkType: "isNotNull",
						errorMsg: "请选择意向工作城市"
					}, {
						name: "type_id",
						checkType: "isNotNull",
						errorMsg: "请选择职业类型"
					}, {
						name: "station_icon",
						checkType: "isNotNull",
						errorMsg: "请选择岗位标签"
					}, {
						name: "free_fare_distance",
						checkType: "isFloatNum",
						errorMsg: "请输入公里数",
						regType: 2,
						maxNum: '',
						unit: '公里'
					},
					{
						name: "address",
						checkType: "isNotNull",
						errorMsg: "请选择所在地址"
					},
					{
						name: "text",
						checkType: "isNotNull",
						errorMsg: "请输入" + this.$t('action.attendantName') + "简介",
						regType: 2
					},
					{
						name: "id_code",
						checkType: "isIdCard",
						errorMsg: "请输入您的身份证号码"
					},
					{
						name: "true_user_name",
						checkType: "isNotNull",
						errorMsg: "请输入您的真实姓名",
						regType: 2
					},
					{
						name: "id_card",
						checkType: "isNotNull",
						errorMsg: "请上传身份证人像面"
					},
					{
						name: "id_card_fan",
						checkType: "isNotNull",
						errorMsg: "请上传身份证国徽面"
					},
					{
						name: "id_card_people",
						checkType: "isNotNull",
						errorMsg: "请上传手持身份证照片"
					},
					{
						name: "license",
						checkType: "isNotNull",
						errorMsg: "请上传资格证书"
					},
					{
						name: "work_img",
						checkType: "isNotNull",
						errorMsg: "请上传工作形象照"
					},
					{
						name: "self_img",
						checkType: "isNotNull",
						errorMsg: "请上传"
					},
				],
				lockTap: false,
			}
		},
		computed: mapState({
			configInfo: state => state.config.configInfo,
		}),
		async onLoad(options) {
			let {
				admin_id = 0,
					is_edit = 0
			} = options
			options.is_edit = is_edit
			this.options = options
			this.form.admin_id = admin_id * 1
			this.$util.showLoading()
			await this.initIndex()
		},
		// #ifdef H5
		destroyed() {
			// #endif
			// #ifndef H5
			onUnload() {
					// #endif
					if (this.timer) clearInterval(this.timer)
				},
				watch: {
					'form.birthday'(birthday) {
						if (birthday) {
							let arr = birthday.split('-')
							let month = arr[1]
							let day = arr[2]
							this.form.constellation = this.$util.getAstro(month, day)
						}
					}
				},
				methods: {
					...mapActions(['getConfigInfo', 'getCoachInfo']),
					...mapMutations(['updateUserItem']),
					async initIndex(refresh = false) {
						if (!this.configInfo.id || refresh) {
							await this.getConfigInfo()
						}
						let selfInd = this.rule.findIndex(item => {
							return item.name === 'self_img'
						})
						this.rule[selfInd].errorMsg = `请上传${this.$t('action.lifeText')}`
						this.$util.setNavigationBarColor({
							bg: this.primaryColor
						})
						await this.getDetail()
						// #ifdef H5
						if (!refresh) {
							this.$jweixin.hideOptionMenu()
						}
						// #endif
					},
					initRefresh() {
						this.initIndex(true)
					},
					async getStationIconSelect() {
						let data = await this.$api.technician.stationIconSelect({
							industry_type: this.form.industry_type
						})
						this.stationList = data

						this.stationIndex = data.findIndex(item => {
							return item.id == this.form.station_icon
						})
						console.log(this.stationIndex, '========> this.stationIndex')
						if (this.stationIndex == -1) {
							this.form.station_icon = ''
						}
					},
					async getCoachIconSelect() {
						let data = await this.$api.technician.coachIconSelect()
						data.unshift({
							id: 0,
							title: `不关联个性标签`
						})
						this.personalityList = data
					},
					async getDetail() {
						await this.getCoachInfo() // 技师端账号登录需要此接口
						let data = this.$util.deepCopy(this.coachInfo)
						this.$util.hideAll()
						this.form.admin_id = data.id && data.admin_id ? data.admin_id * 1 : 0
						await this.getBaseInfo()
						await this.getCoachIconSelect()
						if (!data || (data && !data.id)) {
							this.isLoad = true
							return
						}
						data.city_id = data.city_id || ''
						data.store_name = data.store && data.store.length > 0 ? this.$util.getItems(data.store,
							'title', '、') : ''
						data.store = data.store && data.store.length > 0 ? data.store.map(item => {
							return item.id
						}) : []
						data.type_id = data.type_id || ''
						data.height = data.height * 1 > 0 ? data.height : ''
						if (!data.industry_info || data.industry_info == null) {
							data.industry_type = ''
						}
						data.free_fare_distance = data.free_fare_distance == null ? '' : data.free_fare_distance
						data.custom_balance = data.id_card && data.id_card.length > 0 ? '-1734593' : {}

						let oldData = this.$util.deepCopy(data)
						this.oldData = oldData

						data.birthday = data.birthday * 1 > 0 ? this.$util.formatTime(data.birthday * 1000,
							'YY-M-D') : ''
						let imgArr = ['id_card', 'license', 'self_img']
						imgArr.map(item => {
							data[item] = data[item] && data[item].length > 0 ? data[item].map(
								aitem => {
									return {
										path: aitem
									}
								}) : []
						})
						if (data.id_card && data.id_card.length > 1) {
							data.id_card_fan = [data.id_card[1]]
							data.id_card_people = [data.id_card[2]]
							data.id_card.splice(1, 3)
						}
						let imgArrs = ['work_img', 'video']
						imgArrs.map(item => {
							data[item] = data[item] && data[item].length > 0 ? [{
								path: data[item]
							}] : []
						})

						for (let key in this.form) {
							this.form[key] = data[key]
						}
						if (data.industry_type) {
							this.industryInfo = data.industry_info
						}
						let {
							agent_update_city
						} = this.configInfo
						if (!data.admin_id || agent_update_city) {
							this.cityIndex = this.cityList.findIndex(item => {
								return item.id == data.city_id
							})
							if (this.cityIndex == -1) {
								this.form.city_id = ''
							}
						}
						this.personalityIndex = this.personalityList.findIndex(item => {
							return item.id == data.personality_icon
						})
						this.typeIndex = this.typeList.findIndex(item => {
							return item.id == data.type_id
						})
						if (this.typeIndex == -1) {
							this.form.type_id = ''
						}

						let textArr = ['mobile', 'status']
						textArr.map(item => {
							this[item == 'mobile' ? `old_phone` : 'coach_status'] = data[
								item]
						})
						this.isLoad = true
						let coachInfo = Object.assign({}, this.$util.deepCopy(this.coachInfo), this.$util.pick(data, [
							'lat', 'lng', 'address'
						]))
						this.updateUserItem({
							key: 'coachInfo',
							val: coachInfo
						})
						if (this.configInfo.plugAuth.industrytype == 3) {
							this.getStationIconSelect()
						}
					},
					async getBaseInfo() {
						let {
							career = false
						} = this.configInfo.plugAuth
						if (career) {
							this.typeList = await this.$api.technician.coachTypeSelect()
						}

						let {
							admin_id = 0
						} = this.form
						let {
							agent_update_city
						} = this.configInfo
						if (!admin_id || agent_update_city) {
							let {
								lat = 0, lng = 0
							} = this.location
							let city = await this.$api.base.getCity({
								lat,
								lng
							})
							this.cityList = city
						}

						let carcashinfo = admin_id ? await this.$api.technician.adminCarCashInfo({
							admin_id
						}) : this.configInfo
						this.faree_info = this.$util.pick(carcashinfo, ['free_fare_bear', 'free_fare_distance'])
						if (!this.faree_info.free_fare_bear) {
							this.form.free_fare_distance = ''
						}
					},
					pickerChange(e, key) {
						let ind = e.target.value
						if (key === 'birthday') {
							let unix = this.$util.DateToUnix(ind)
							if (unix > new Date(Math.ceil(new Date().getTime())) / 1000) {
								this.$util.showToast({
									title: `不能选择未来时间哦`
								})
								return
							}
							this.form[key] = ind
							return
						}
						if (ind == -1) return
						this[`${key}Index`] = ind
						let {
							id
						} = this[`${key}List`][ind]
						if (key === 'industry') {
							this.form[`${key}_type`] = id
						} else if (['station', 'personality'].includes(key)) {
							this.form[`${key}_icon`] = id
						} else {
							this.form[`${key}_id`] = id
						}
						if (key === 'type') {
							this.getStationIconSelect()
						}
					},
					// 发送验证码
					async toSend() {
						let {
							authTime
						} = this
						if (authTime) return
						let {
							mobile = ''
						} = this.form
						if (mobile == null || !/^(1[0-9]{10})$/.test(mobile)) {
							this.$util.showToast({
								title: mobile == null ? `请输入手机号` : `${mobile} 手机号无效`
							});
							return;
						}
						if (this.lockTap) return
						this.lockTap = true
						this.$util.showLoading()
						try {
							await this.$api.user.sendShortMsg({
								phone: mobile
							})
							this.$util.hideAll()
							this.lockTap = false
							let time = 60
							this.timer = setInterval(() => {
								if (time === 0) {
									clearInterval(this.timer)
									return
								}
								time--
								this.authTime = time
							}, 1000)
						} catch (e) {
							setTimeout(() => {
								this.lockTap = false
								this.$util.hideAll()
							}, 2000)
						}
					},
					imgUpload(e) {
						let {
							imagelist,
							imgtype
						} = e;
						this.form[imgtype] = imagelist;
					},
					// 选择地区
					async toChooseLocation() {
						// #ifdef APP-PLUS
				this.$util.goUrl({
					url: `/user/pages/choose/addr?from=addr`
				})
				// if (plus.os.name == 'Android' && plus.navigator.checkPermission(
				// 		'android.permission.ACCESS_FINE_LOCATION') ===
				// 	'undetermined') {
				// 	this.$refs.app_check_item.open()
				// } else {
				// 	this.toConfirmChooseLoca()
				// }
						// #endif
						// #ifndef APP-PLUS
						this.toConfirmChooseLoca()
						// #endif
					},
					async toConfirmChooseLoca() {
						// #ifdef MP-WEIXIN
						let privacyCheck = this.$refs.user_privacy.check()
						if (privacyCheck) {
							this.$refs.user_privacy.open()
							return
						}
						// #endif 
						let {
							lat,
							lng,
							address
						} = await this.$util.chooseLocation(1)
						if (!address) return
						this.form.lat = lat
						this.form.lng = lng
						this.form.address = address
					},
					//表单验证
					validate(param) {
						let {
							plugAuth
						} = this.configInfo
						let {
							free_fare_bear,
							free_fare_distance
						} = this.faree_info
						let {
							industryInfo
						} = this
						let typeArr = ['height', 'weight', 'birthday']
						let validate = new this.$util.Validate();
						this.rule.map(item => {
							let {
								name,
							} = item
							if (typeArr.includes(name)) {
								if (industryInfo[name]) {
									validate.add(param[name], item)
								}
							} else if (name === 'work_time') {
								if (industryInfo.employment_years) {
									validate.add(param[name], item)
								}
							} else if (name === 'license') {
								if (industryInfo.qualification) {
									validate.add(param[name], item)
								}
							} else if (name == 'free_fare_distance') {
								if (param[name]) {
									if (free_fare_bear == 1 || free_fare_bear == 3) {
										item.maxNum = free_fare_distance * 1
									}
									validate.add(param[name], item)
								}
							} else if (name == 'type_id') {
								if (plugAuth.career) {
									validate.add(param[name], item)
								}
							} else if (name == 'station_icon') {
								if (plugAuth.industrytype == 3) {
									validate.add(param[name], item)
								}
							} else if (name == 'text') {
								if (plugAuth.dispatchother) {
									validate.add(param.min_price, {
										checkType: "isMoney",
										regType: 2,
										errorMsg: "请输入最低价"
									})
									validate.add(param.max_price, {
										checkType: "isMoney",
										regType: 2,
										errorMsg: "请输入最高价"
									})
									if (param.min_price * 1 > param.max_price * 1) {
										validate.add(' ', {
											checkType: "isNotNull",
											regType: 2,
											errorMsg: "最低价不能大于最高价"
										})
									}
									validate.add(param[name], item)
								} else {
									validate.add(param[name], item)
								}
							} else {
								validate.add(param[name], item)
							}
						})
						let message = validate.start();
						return message;
					},
					async submit() {
						let param = this.$util.deepCopy(this.form)
						let arr = ['id_card', 'id_card_fan', 'id_card_people',
							'work_img', 'video'
						]
						arr.map(item => {
							param[item] = param[item] && param[item].length >
								0 ? param[item][0].path : ''
						})
						param.license = param.license && param.license.length > 0 ? param.license.map(item => {
							return item.path
						}) : []
						param.self_img = param.self_img.map(item => {
							return item.path
						})
						let msg = this.validate(param);
						if (msg) {
							this.$util.showToast({
								title: msg
							});
							return
						}
						param.free_fare_distance = param.free_fare_distance || 0
						param.birthday = param.birthday ? this.$util.DateToUnix(param.birthday) : ''
						param.id_card = [param.id_card, param.id_card_fan, param.id_card_people]
						delete param.id_card_fan
						delete param.id_card_people
						delete param.admin_id
						delete param.city
						delete param.store_name
						let {
							old_phone
						} = this
						let {
							short_code_status,
						} = this.configInfo
						if (short_code_status && old_phone != param.mobile && (param
								.short_code == null || param
								.short_code
								.length != 6)) {
							this.$util.showToast({
								title: `请输入6位数短信验证码`
							})
							return
						}
						if (!short_code_status || old_phone == param.mobile) {
							delete param.short_code
						}


						let newData = {}
						let newNum = 0
						let {
							auth_status
						} = this.oldData

						if (param.id && auth_status == 2) {
							let arr = ['address', 'lat', 'lng']
							let oldArr = JSON.stringify(this.$util.pick(this.oldData, arr))
							let newArr = JSON.stringify(this.$util.pick(param, arr))
							for (let i in param) {
								let isChange = arr.includes(i) ? oldArr !== newArr : JSON.stringify(param[i]) !==
									JSON.stringify(this.oldData[i])
								if (isChange) {
									newNum++
								}
								newData[i] = (i !== 'id' && i !== 'status' && i !== 'industry_type' && !isChange) ?
									'-1734593' : param[i]
							}
							if (newNum) {
								param = newData
							}
						}

						if (param.id && auth_status == 2 && !newNum) {
							this.$util.showToast({
								title: `您暂未修改任何内容哦，请修改后再保存！`
							})
							return
						}

						if (param.id && auth_status != 2) {
							delete param.custom_balance
						}

						if (this.lockTap) return
						this.lockTap = true
						this.$util.showLoading()
						try {
							await this.$api.technician.coachUpdateV2(param)
							this.$util.hideAll()
							this.$util.showToast({
								title: `提交成功`
							})
							if (this.timer) {
								clearInterval(this.timer)
							}
							setTimeout(() => {
								if (getCurrentPages().length > 1) {
									this.$util.back()
								}
								this.$util.goUrl({
									url: '/technician/pages/mine',
									openType: `reLaunch`
								})
							}, 2000)
						} catch (e) {
							setTimeout(() => {
								this.lockTap = false
								this.$util.hideAll()
							}, 2000)
						}

					}
				}
		}
</script>


<style lang="scss">
	.apply-pages {
		.apply-form {
			.item-text {
				width: 250rpx
			}

			.item-text.tips {
				width: 200rpx
			}
		}
	}
</style>